<?php
require_once("levelView.php");
require_once(CORE_DIR.'levelModel.php');

class addAction extends authAction{

	function __construct(){
		$this->view = new levelView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$lModel = new levelModel();	 	
		
		if (isset($get["level"]) && isset($get["pointTypeId"]) && isset($get["points"])){
			$level = $get["level"];
			$pointTypeId = $get["pointTypeId"];
			$points = $get["points"];
			$levelTitle = htmlspecialchars($get["title"], ENT_QUOTES);
			$levelImagePath = htmlspecialchars($get["imagePath"], ENT_QUOTES);
			
			$lastInserId = $lModel->addLevel($level, $pointTypeId, $points, $levelTitle, $levelImagePath);
			$status = 0;
			$id = 0;
			if ($lastInserId > 0){
				$status = 1;
				$id = $lastInserId;
			}
			
			$this->view->setProperty("status", $status);
			$this->view->setProperty("id", $id);
			$this->view->showAddLevel();
		}
		else{
			$this->view->showBadCmd();
		}	
			
	}
}
?>